package main.java.tmi.productAdjust.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import main.java.tmi.common.service.UserVO;
import main.java.tmi.productAdjust.service.ProductAdjustService;
import main.java.tmi.productAdjust.service.ProductAdjustVO;

import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * 사용자 로그인 처리하는 서비스 구현 클래스
 *
 * @author min™
 * @since 2011. 07. 24
 *
 */
@Service
public class ProductAdjustServiceImpl implements	ProductAdjustService {

	
	@Resource(name = "productAdjustDAO")
	protected ProductAdjustDAO productAdjustDAO;

	public List<ProductAdjustVO> getProductAdjustView(Map<String,String> param) throws SQLException {
		
		return productAdjustDAO.getProductAdjustView(param);
	}	
	
	public int getProductAdjustViewCount(Map<String,String> param) throws SQLException {
		
		return productAdjustDAO.getProductAdjustViewCount(param);
	}
	
	public Map<String,String> getProductAdjustDetailView(Map<String,String> param) throws SQLException {
		
		return productAdjustDAO.getProductAdjustDetailView(param);
	}

	@Override
	public boolean addProductAdjust(Map<String, String> param) throws Exception {
		boolean resultData = true; 
		UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
		String userIdTmp = "";
		if(userInfo != null) {
			userIdTmp = userInfo.getUserId();
		} else {
			userIdTmp = "SYSTEM";
		}
		
		try{
			param.put("registId", userIdTmp);
			String saveStatus = param.get("saveStatus").toString();
	    	System.out.println("=======================> saveStatus"+saveStatus);
	    	
	    	if(saveStatus.equals("SAVE")){
	    		productAdjustDAO.addProductAdjust(param);
	    	}else if(saveStatus.equals("UPDATE")){
	    		productAdjustDAO.modifyProductAdjust(param);
	    	}
		}catch(Exception e){
			resultData = false;
		}
		return resultData;
	}
	
	//키값
	@Override
	public String productAdjustDupChk(Map<String, String> param) throws Exception {
		// TODO Auto-generated method stub
		return productAdjustDAO.productAdjustDupChk(param);
	}
	
	@Override
	public boolean delProductAdjust(Map<String, String> param) throws Exception {
		boolean resultData = true; 
		try{
			productAdjustDAO.delProductAdjust(param);
		}catch(Exception e){
			resultData = false;
		}
		return resultData;
	}
}
